package com.hqd.ch03.v49.boot.context.config;

import com.hqd.ch03.v49.core.log.LogMessage;
import org.apache.commons.logging.Log;

public enum ConfigDataNotFoundAction {

    /**
     * Throw the exception to fail startup.
     */
    FAIL {
        @Override
        void handle(Log logger, ConfigDataNotFoundException ex) {
            throw ex;
        }

    },

    /**
     * Ignore the exception and continue processing the remaining locations.
     */
    IGNORE {
        @Override
        void handle(Log logger, ConfigDataNotFoundException ex) {
            logger.trace(LogMessage.format("Ignoring missing config data %s", ex.getReferenceDescription()));
        }

    };

    /**
     * Handle the given exception.
     *
     * @param logger the logger used for output {@code ConfigDataLocation})
     * @param ex     the exception to handle
     */
    abstract void handle(Log logger, ConfigDataNotFoundException ex);

}

